# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: zelinchen

from coin.exchange.base.kr_rest.private_client_base import PrivateClientBase
from coin.exchange.deribit_v1.kr_rest.futures_product import DeribitFuturesProduct
from coin.exchange.deribit_v2.rest.native_private_client import DeribitFuturesNativePrivateClient
from coin.exchange.deribit_v2.rest.private_client import DeribitFuturesPrivateParser


class DeribitFuturesPrivateClient(PrivateClientBase):
  ProductType = DeribitFuturesProduct

  def __init__(self, key_file):
    super().__init__()
    self.nprivc = DeribitFuturesNativePrivateClient(key_file=key_file)

  def query_account_balance_impl(self):
    update_msg_total = []
    for currency in ('BTC', 'ETH'):
      update = self.nprivc.query_account_summary(currency)
      update.msg = DeribitFuturesPrivateParser.parse_balance(update.msg)
      update_msg_total.append(update.msg)
    update.msg = DeribitFuturesPrivateParser.parse_balance_total(update_msg_total)
    return update

  def query_account_position_impl(self):
    update_msg_total = []
    for currency in ('BTC', 'ETH'):
      update = self.nprivc.query_positions(currency)
      update.msg = DeribitFuturesPrivateParser.parse_account_position(update.msg)
      update_msg_total.append(update.msg)
    update.msg = DeribitFuturesPrivateParser.parse_position_total(update_msg_total)
    return update

  def query_cancel_product_impl(self, product):
    raise NotImplementedError()

  def query_fills_impl(self, product):
    raise NotImplementedError()

  def query_submit_impl(self, product):
    raise NotImplementedError()
